/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.srcptit.trainning.b1;

import static com.srcptit.trainning.b1.B7_nguyenToThuanNghichFibo.soTN;

/**
 *
 * @author Administrator
 */
public class B8_nguyenToVaKhongGiam {
    public static void main(String[] args) {
        lietKe(7);
    }
    static boolean isPrime(long n){
        if(n<2) return false;
        if(n==2) return true;
        if(n%2==0) return false;
        for(long i=3;i<=(long)Math.sqrt(n);i+=2)
            if(n%i==0) return false;
        return true;
    }
    static boolean chuSo(long n){
        long t;
        while(n>0){
            t = n%10;
            if(!isPrime(t)) return false;
            n /= 10;
        }
        return true;
    }
    static boolean khongGiam(long n){
        int truoc = (int)n%10, sau;
        while(n>0){
            sau = truoc;
            truoc = (int) (n%10);
            if(truoc>sau) return false;
            n /= 10;
        }
        return true;
    }
    static void lietKe(int n){
        long n1 = (long)Math.pow(10,n-1);
        long n2 = (long)Math.pow(10, n);
        for(long i=n1;i<n2;i++)
            System.out.print((chuSo(i) && isPrime(i) && khongGiam(i))?("\n"+i):(""));
    }
}
